<?php

namespace frontend\controllers;

use Yii;
use common\models\Help;
use yii\data\ActiveDataProvider;
use frontend\controllers\base\BaseController;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use common\models\HelpColumn;

/**
 * HelpController implements the CRUD actions for Help model.
 */
class HelpController extends BaseController
{
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['POST'],
                ],
            ],
        ];
    }

    /**
     * Lists all Help models.
     * @return mixed
     */
    public function actionIndex()
    {
        $column=HelpColumn::find()->asArray()->all();
        $id=max((int)$_GET['pid'],1);
        $data=Help::find()->with('helpColumn')->where('cid='.$id)->asArray()->one();
        return $this->render('index', [
            'column'=>$this->dataSort($column),
            'data'=>$data
        ]);
    }

    /**
     * Displays a single Help model.
     * @param string $id
     * @return mixed
     */
    public function actionView($id)
    {
        return $this->render('view', [
            'model' => $this->findModel($id),
        ]);
    }


    /**
     * Finds the Help model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param string $id
     * @return Help the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id)
    {
        if (($model = Help::findOne($id)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }
}
